package wifiunion.com.notice.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import wifiunion.com.notice.R;


/**
 * 通用确认对话框
 *
 * @author dqcao
 */
public class OperationDialog extends Dialog {

    private Context context;
    private TextView titleName;
    private TextView cancelTxt;

    private TextView firstoptTv;
    private TextView secondoptTv;


    public OperationDialog(Context context) {
        super(context, R.style.alert_dialog);
        this.context = context;
        LayoutInflater li = LayoutInflater.from(context);
        ViewGroup contentView = (ViewGroup) li.inflate(
                R.layout.dialog_operation, null);
        contentView.bringToFront();


        titleName = (TextView) contentView.findViewById(R.id.tv_title_name);
        cancelTxt = (TextView) contentView.findViewById(R.id.cancel_txt);
        firstoptTv = (TextView) contentView.findViewById(R.id.tv_firstoptval);
        secondoptTv = (TextView) contentView.findViewById(R.id.tv_secondoptval);

        cancelTxt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setCanceledOnTouchOutside(false);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.gravity = Gravity.CENTER;
        onWindowAttributesChanged(lp);
        setContentView(contentView);


    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = getContext().getResources().getDimensionPixelSize(
                R.dimen.dp_354);
        lp.gravity = Gravity.CENTER;
        getWindow().setAttributes(lp);
    }

    public void setTitleMsg(String msg) {
        if (titleName != null) {
            titleName.setText(msg);
        }
    }

    public void setCancleText(String text) {
        if (text != null) {
            cancelTxt.setText(text);
        }
    }

    public void setFirstoptTv(String content) {
        firstoptTv.setText(content);
    }

    public void setSecondoptTv(String content) {
        secondoptTv.setText(content);
    }


    public void setCancelListener(View.OnClickListener okListener) {
        if (cancelTxt != null) {
            cancelTxt.setOnClickListener(okListener);
        }
    }

    public void setFirstOptListener(View.OnClickListener okListener) {
        if (firstoptTv != null) {
            firstoptTv.setOnClickListener(okListener);
        }
    }

    public void setSecondOptListener(View.OnClickListener okListener) {
        if (secondoptTv != null) {
            secondoptTv.setOnClickListener(okListener);
        }
    }

}
